home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 051-075 / scopedisk66 / gif2iff / convert.doc < prev    next >
Text File  |  1995-03-19  |  5KB  |  134 lines

  1.      
  2.      
  3.      I was exploring BBS's one day and came across one for IBM's that
  4.      had several digitized images in GIF format. Out of curiousity, I
  5.      downloaded a couple and tried to display them using 'giffy'.
  6.      Nothing coherent. Still curious I put together a quick program to
  7.      decode GIF (which uses a form LZW compression-interesting in
  8.      itself) and saved the pictures in a more simple format. When I
  9.      make reference to TMP files in this doc, I'm referring to this
  10.      format, which is as follows:
  11.      
  12.       
  13.      
  14.      struct TMPFILE
  15.      {
  16.       SHORT ImageWidth,ImageHeight,NoOfColorRegisters;
  17.       Struct COLORREGISTER ColorRegisters[NoOfColorRegisters];
  18.       UBYTE Image[ImageHeight][ImageWidth];
  19.      }
  20.      
  21.      where struct COLORREGISTER is
  22.      
  23.      struct COLORREGISTER
  24.      {
  25.       UBYTE red;
  26.       UBYTE green;
  27.       UBYTE blue;
  28.      }
  29.      ** Note that the picture is Image[y][x] not Image[x][y] **
  30.      
  31.      
  32.      The Image array indexes into the ColorRegisters array, which hold
  33.      the actual color values. For example-The red component of a pixel
  34.      (x,y) is given by the value of   ColorRegisters[Image[y][x]].red.
  35.      A value of 255 is all the  way  on.  A  value of 0 is all the way
  36.      off. Since the Amiga can only display  4 bits per color component
  37.      the following equation should be used:
  38.      
  39.        temp=ColorRegisters[Image[y][x]].red
  40.        RedComponent = (tmp>>4)&0x0f; 
  41.      
  42.      And'ing the value with 0x0f  probably  isn't  necessary but helps
  43.      conceptually.
  44.      
  45.      
  46.      If the Image  is  Interlaced,  GIFtoTMP  will  use  exit(5)  upon
  47.      completion in addition to a  written  message. This allows you to
  48.      check for this condition  in  a  CLI  script  file.  See the file
  49.      'convert' for an example.  The  file  Unlace  can then be used to
  50.      un-interlace the image. 
  51.      
  52.      
  53.      The last program, TMPtoIFF,  is  the  heart  of this series. When
  54.      converting the TMP file  into  an  Amiga  IFF file, the number of
  55.      color registers must  be  reduced  (usually  from  256). TMPtoIFF
  56.      currently offers three algorithms to do this:
  57.      
  58.        Popularity-Merely chooses the top most used colors
  59.      
  60.        Median Cut-Thinks of the colors as points in three dimensional
  61.                   space (Red,Green+Blue) and draws a box that
  62.                   encloses all points. The program then divides that
  63.                   box into two boxes with an equal number of colors in
  64.                   each side. (A pure white screen would only have one
  65.                   color-even though it is used in thousands of pixels)
  66.                   The boxes are continuously divided along their
  67.                   longest axis until there are as many boxes as the
  68.                   number of colors that you want. Then the colors in
  69.                   each box are averaged and those values are used in
  70.                   the final color map.
  71.      
  72.        Weighted Median Cut-I modified the above algorithm so that as
  73.                   it's dividing each box along its longest axis, it
  74.                   tries to put an equal number of pixels in each side
  75.                   (which of course is impossible to do exactly)
  76.                   This produces averaged colors closer to the majority
  77.                   colors, but also provides the variety that the 
  78.                   Median Cut does
  79.      
  80.      After one of  the  above  algorithms  is  run,  each pixel in the
  81.      original image is replaced with  the  closest  value in the final
  82.      color map. If a HAM image is  requested,  the program uses one of
  83.      the above algorithms to produce  the  color register values. This
  84.      works very well in practice.
  85.      
  86.      
  87.      Summary of Files:
  88.      
  89.         GIFtoTMP    Converts GIF files into TMP files
  90.      
  91.         Unlace      Will unlace a TMP file. Use only if
  92.                     GIFtoTMP indicates it as such
  93.      
  94.         TMPtoIFF    Converts TMP files into IFF files
  95.      
  96.         convert     the CLI file I use to convert the images
  97.                     usage as such: 
  98.      
  99.                 convert giffilepath giffilename [options for TMPtoIFF]
  100.      
  101.      
  102.      The usage of each file (except  convert)  can  be found be typing
  103.      the name of each file and pressing return.
  104.      
  105.      I've only tried this progam on 320x200 and 320x240 images. If you
  106.      try larger  images,  like  640x400  make  sure  you have a lot of
  107.      memory. Although I wrote this program specifically for converting 
  108.      IBM GIF images to Amiga  IFF  images,  it  will hopefully work on
  109.      most GIF files. Let me know if you  have any problems. One that I
  110.      already know of  is  if  you  specify  a  final  image  of  5 bit
  111.      planes(32 colors) and  the  original  GIF  image has less than 32
  112.      colors.
  113.      
  114.      
  115.                                   Mark Podlipec
  116.                                   111-4 BroadMeadow Rd
  117.                                   Marlboro MA  01752
  118.      
  119.      
  120.                                   
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.